import ajax from "./ajax";
import axios from "axios";

// 登陆相关请求
let baseUrl = 'http://localhost:3000/';
export function reqLogin(username, password) {
    return ajax(baseUrl + 'role', { username, password });
}
export function reqAddUser(user) {
    return ajax(baseUrl + 'role', { user }, 'POST');
}
// 类别相关请求
export function reqGetCategory() {
    return ajax(baseUrl + 'category');
}
// 类别相关请求
export function reqAddCategory(data) {
    return ajax(baseUrl + 'category', data, 'POST');
}
export function reqDelCategory(id) {
    return axios({
        'url': baseUrl + "category/" + id,
        'method': "delete",
    });
}
export function reqUpdataCategory(id, data) {
    // return ajax(baseUrl+"category/" + id,data,'patch')
    return axios({
        'url': baseUrl + "category/" + id,
        'method': "patch",
        'data': data
    });
}
// 商品相关请求
export function reqProduction(id) {
    if (id) {
        return ajax(baseUrl + 'products/?id=' + id);
    } else {
        return ajax(baseUrl + 'products/');
    }
}
// 模糊搜索
export function reqSearchProduction(data) {
    return ajax(baseUrl + 'products/?q=' + data);
}
// 上架下架
export function reqUpDownProduction(id, data) {
    return ajax(baseUrl + "products/" + id, data, 'patch')
}
export function reqAddProduction(data) {
    return ajax(baseUrl + "products", data, 'post')
}
// 获得图标数据
export function reqGetEcharts() {
    return ajax(baseUrl + 'Echarts');
}